//
//  MAAdvView.m
//  MateAdv
//
//  Created by 茶 on 2023/9/7.
//

#import "MAAdvView.h"
#import "MAAdvMapView.h"
#import "MAAdvTipView.h"

@interface MAAdvView ()

@property (nonatomic, strong) MAAdvMapView *mapView;
@property (nonatomic, strong) UIButton *diceBtn;


@end

@implementation MAAdvView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initInterface];
    }
    return self;
}

- (void)initInterface {
    _mapView = [MAAdvMapView new];
    [self addSubview:_mapView];
    [_mapView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (SCREEN_HEIGHT <= 812) {
            make.width.mas_equalTo(375 * (SCREEN_HEIGHT / 844));
            make.centerX.mas_equalTo(0);
        } else if (SCREEN_HEIGHT > 812) {
            make.width.mas_equalTo(375);
            make.centerX.mas_equalTo(0);
        } else {
            make.left.right.mas_equalTo(0);
        }
        make.bottom.mas_equalTo(self.mas_safeAreaLayoutGuideBottom);
        make.top.mas_equalTo(self.mas_safeAreaLayoutGuideTop);
    }];
    
    [_mapView.diceBtn addTarget:self action:@selector(diceEvent) forControlEvents:UIControlEventTouchUpInside];
    MAWeakify(self);
    _mapView.endBlock = ^{
        MAStrongify(self);
        MABlock(self.endBlock);
    };
    _mapView.tipBlock = ^(NSUInteger index) {
        MAStrongify(self);
        MABlock(self.tipBlock, index);
    };
}

- (BOOL)isPlay {
    if (_mapView.heNumber > 0 || _mapView.sheNumber > 0) {
        return YES;
    }
    return NO;
}

- (void)diceEvent {
    UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
    [generator impactOccurred];
    
    [_mapView diceChange];
    
    MABlock(self.diceBlock);
}


@end
